<%@ page language="java" import="java.util.*, java.io.*, 
	org.apache.ibatis.io.*,
	org.apache.ibatis.session.*, 
	static com.expmanage.actions.utils.DatabaseConfigure.*,
	com.expmanage.models.*" contentType="text/html;charset=gb2312" 
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>学生信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
</head>

  <body>
  	<%
		if (session.getAttribute("user") == null
				|| !session.getAttribute("user").equals("root_manager")
				|| !session.getAttribute("role").equals("manager")) {
	%>
		<script language="javascript">
			alert("需要登录");
			window.open("index.jsp", "_self");
		</script>
		<%
		}
		%>
  
  	<%!
  	void loadStudents(JspWriter out){
		if(sqlSessionFactory!=null){
			SqlSession sqlsession = sqlSessionFactory.openSession();
       		try {
           		StudentMapper mapper = sqlsession.getMapper(StudentMapper.class);
           		List<Student> students = mapper.selectStudentAll();
           		int i = 0; 
           		for (Student student : students) {
           			int sid = student.getSid();
               		out.print("<tr><td>"+ sid + "</td>"
               			+ "<td>"+ student.getName() + "</td>" 
               			+ "<td>"+ student.getSchoolid() + "</td>" 
               			+ "<td>"+ student.getIdnumber() + "</td>" 
               			+ "<td>"+ student.getEmail() + "</td>" 
               			+ "<td>"+ student.isChecked() + "</td>"
               			+ "<td><input type=\"checkbox\" value=\"" +
               					sid + "\" name=\"sid_check_list\"></td>" +
               			"<td><input type=\"checkbox\" value=\"" +
               					sid + "\" name=\"sid_uncheck_list\"></td>" +
               			"<td><input type=\"checkbox\" value=\"" +
               					sid + "\" name=\"sid_del_list\"></td>" +
               			"</td></tr>");
            	}
        	} catch(Throwable e){
        		e.printStackTrace();
       		} finally {
           		sqlsession.close();
       		}
       	}else{
       		//输出错误
      	}
  	}
  	%>
  	<form id="forms" name="forms" action="checkStudents.action"
		method="POST">
    	<table>
    	<tr><td>学生信息：</td><td><input type="submit" value="确认学生名单"/></td></tr>
    	</table>
    	<table border=1>
    	<tr><td>Sid</td><td>Name</td>
    		<td>学号</td><td>身份证</td><td>邮箱</td><td>已验证</td>
    		<td>验证</td><td>取消验证</td><td>删除</td>
    	</tr>
    	<%
		if (session.getAttribute("user").equals("root_manager")) {
			loadStudents(out);
		}
		%>
		</table>
	</form>
  </body>
</html>
